package bean;

import java.io.Serializable;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

import model.User;

import org.springframework.stereotype.Component;

import service.UserService;

@Component
@ManagedBean(name="userBean")
@SessionScoped
public class UserBean implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -3656406433972693700L;
	
	public UserBean() {
		super();
	}

	@ManagedProperty(value = "#{userService}")
	private UserService userService;

	private User tempUser;
	private Boolean isLoggedIn = false;
	private Boolean isRegistered = false;
	private User getUserInfo;
	
	@PostConstruct
	public void init(){
		tempUser = new User();
	}
			
	public void register(){
		Boolean result = userService.register(tempUser);
		isRegistered=result;
	}
	
	public Boolean login(){
		Boolean result = userService.login(tempUser);
		isLoggedIn = result;
		return result;
	}
	
	public User getUserInfo(){
		
		getUserInfo = userService.getUserInfo(tempUser);
		return getUserInfo;
	}
	
	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	
	public User getTempUser() {
		return tempUser;
	}

	public void setTempUser(User tempUser) {
		this.tempUser = tempUser;
	}

	public Boolean getIsLoggedIn() {
		return isLoggedIn;
	}

	public void setIsLoggedIn(Boolean isLoggedIn) {
		this.isLoggedIn = isLoggedIn;
	}

	public Boolean getIsRegistered() {
		return isRegistered;
	}

	public void setIsRegistered(Boolean isRegistered) {
		this.isRegistered = isRegistered;
	}

	public User getGetUserInfo() {
		return getUserInfo;
	}

	public void setGetUserInfo(User getUserInfo) {
		this.getUserInfo = getUserInfo;
	}
	
	}
